<script>
    let activeEffect
    class Dep {
        constructor(value){
            this.subscribers = new Set()
            this._value = value
        }
        get value() {
            this.depend()
            return this._value
        }
        set value(newValue) {
            this._value =  newValue
            this.notify()
        }
        depend() {
            if(activeEffect) {
                this.subscribers.add(activeEffect)
            }
        }

        notify() {
            this.subscribers.forEach(effect => {
                effect()
            })
        }
    }
    const watchEffect = (effect) => {
        activeEffect = effect
        effect()
        activeEffect = null
    }

    let dep = new Dep('hello')

    watchEffect(() => {
        console.log(dep.value)
    })

    dep.value = 'changed!'
</script>